<template>
    <div class="tableDiv">
        <el-collapse v-model="historyactiveName" accordion>
            <el-collapse-item
              :title="gethospital(item.hospitalName) + '  ' + '顾客编号：' + item.visitNum + ' 登记日期：' + parseTime(item.createTime) + ' 状态：' + getDiagnosisStatusLabel(item.status) + ' 诊断：' + item.doctorDiagnosis"
              v-for="(item, index) in baseInfoData" :key="index" :name="index" v-if="item.visitNum != basicInfo.visitNum">
              <template slot="title">
                <div style="width: 100%;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;">
                {{gethospital(item.hospitalName) }}顾客编号：{{item.visitNum}}  登记日期：{{parseTime(item.createTime)}} 状态：{{getDiagnosisStatusLabel(item.status)}}  诊断：{{item.doctorDiagnosis}}
              </div>
              </template>
              <el-row style="font-size:15px">
                <el-col :span="6">顾客编号:{{ item.visitNum }}</el-col>
                <el-col :span="3">顾客ID:{{ item.patientId }}</el-col>
                <el-col :span="3">手机:{{ item.patientPhone }}</el-col>
                <el-col :span="3">状态:{{ matchDict("sys_diagnosis_status", item.status) }}</el-col>
                <el-col :span="3">卡号:{{ item.cardNumber }}</el-col>
                <el-col :span="3">顾客分类:{{ matchDict("sys_patient_sort", item.customerSort) }}</el-col>
                <el-col :span="3">皮肤色度:{{ matchDict("sys_skin_tone", item.tone) }}</el-col>
              </el-row>
              <el-row style="font-size:15px">
                <el-col :span="6">患者地址:{{ item.area }}</el-col>
                <el-col :span="6">详细地址:{{ item.address }}</el-col>
                <el-col :span="3">顾客性质:{{ matchDict("sys_patient_properties", item.properties) }}</el-col>
                <el-col :span="3">职业:{{ item.job }}</el-col>
                <el-col :span="3">微信号:{{ item.wxNum }}</el-col>
              </el-row>
              <el-row style="font-size:15px">
                <el-col :span="24">就诊门诊:<span style="color:red;font-size:15px;font-weight:700;">{{ item.deptName }}</span></el-col>
            </el-row>
              <el-row style="font-size:15px">
                <el-col :span="24">医生诊断:<span style="color:red;font-size:15px;font-weight:700;">{{ item.doctorDiagnosis }}</span></el-col>
            </el-row>
            <el-row style="font-size:15px">
                <el-col :span="24">医生方案:<span style="color:red;font-size:15px;font-weight:700;">{{ item.doctorPlan }}</span></el-col>
            </el-row>
            <el-row style="font-size:15px">
                <el-col :span="6">诊断医生:{{ item.doctor }}</el-col>
                <el-col :span="6">诊断时间:{{ item.doctorTime }}</el-col>
                <el-col :span="6">方案总额:{{ item.doctorTotalExpenses }}</el-col>
                <el-col :span="6">治疗费用:{{ item.doctorTreatmentExpenses }}</el-col>
            </el-row>
              <el-row style="font-size:15px">
                <el-col :span="4">备注:{{ item.remark }}</el-col>
              </el-row>
              <el-row style="font-size:15px;float:right">
                <el-button size="mini" @click="addPlan(item.visitNum)" type="primary" style="margin-left:15px;margin-bottom:10px;"
                :disabled="item.doctorDiagnosis?false:true">引用方案</el-button>
            </el-row>
            </el-collapse-item>
          </el-collapse>
    </div>
  </template>

  <script>
  import store from "@/store";
  import {  getList } from "@/api/doctorWorkstation/diagnosisList";
  export default {
    name: "treatmentHistory",
    components: {},
    props: ["basicInfo",'type'],
    dicts: ['sys_diagnosis_status',
      'sys_user_sex', "photo_upload_type",
      "photo_lighting_type",
      "sys_face_part",
      "sys_patient_properties",
      "sys_skin_tone", "sys_patient_sort",
      'sys_treatment_reaction', 'sys_treatment_effect'],
    data() {
      return {
        historyactiveName:1,
        baseInfoData: [],
        treatmentRecordQueryParams: {
          pageNum: 1,
          pageSize: 9999,
          visitNum: '',
          patientId: '',
        },

      };
    },
    created() {

    },
    mounted() {
      console.log(this.basicInfo)
      if (this.basicInfo) {
        this.treatmentRecordQueryParams.patientId = this.basicInfo.patientId
        this.getPatientList()
      }

    },
    methods: {
        gethospital(str) {
      if (str) {
        return str
      } else {
        return ''
      }
    },
          /** id转化成对应的文字 */
    matchDict: function (key, id) {
      let _this = this;
      const result = _this.dict.type[key];
      let textValue = "";
      result.forEach((item) => {
        if (item.raw.dictValue == id) {
          textValue = item.raw.dictLabel;
        }
      });
      return textValue;
    },
    addPlan(data){
      if(this.type==1){
         let infos={
              type:1,
              data:data
         }
         this.$emit('comfirmCitate',infos)
      }else{
        this.$emit('comfirmCitate',data)
      }

    },
          //获取诊断状态字典值对应的label
    getDiagnosisStatusLabel(status) {
      let label = ''
      this.dict.type.sys_diagnosis_status.forEach((item) => {
        if (item.value == status) {
          label = item.label
        }
      })
      return label

    },
      getTreatmentReactionText(value) {
        let text = ''
        if (value.includes(',')) {
          let data = value.split(',')
          data.forEach((item, index) => {
            this.dict.type.sys_treatment_reaction.forEach((row) => {
              if (item === row.value) {
                if (index + 1 < data.length) {
                  text = `${text + row.label},`
                } else {
                  text += row.label
                }
              }
            })
          })
        } else {
          this.dict.type.sys_treatment_reaction.forEach((row) => {
            if (value === row.value) {
              text = row.label
            }
          })
        }
        return text
      },

      // 获取顾客治疗列表
      getPatientList() {
      const patientId = this.treatmentRecordQueryParams.patientId
      const queryParams = { pageNum: 1, pageSize: 9999, patientId: patientId }
      getList(queryParams).then((response) => {
          this.baseInfoData = response.rows
          this.baseInfoData.forEach(item => {
            if (item.consultationDiagnosis.includes(';')) {
              let Mobject = ''
              item.consultationDiagnosis.split(';').forEach(it => {
                Mobject += it + '<br>'
              })
              item.consultationDiagnosisValue = Mobject
            } else {
              item.consultationDiagnosisValue = item.consultationDiagnosis
            }
            if (item.doctorDiagnosis.includes(';')) {
              let MobjectDoctor = ''
              item.doctorDiagnosis.split(';').forEach(it => {
                MobjectDoctor += it + '<br>'
              })
              item.doctorDiagnosisValue = MobjectDoctor
            } else {
              item.doctorDiagnosisValue = item.doctorDiagnosis
            }
            if (item.doctorPlan != null) {
              if (item.doctorPlan.includes(';')) {
                let MobjectText = ''
                item.doctorPlan.split(';').forEach(it => {
                  MobjectText += it + '<br>'
                })
                item.doctorPlanValue = MobjectText
              } else {
                item.doctorPlanValue = item.doctorPlan
              }
            }
          });

        }
      )


    },


    },
  };
  </script>
  <style scoped lang="scss">
  .tableDiv {

  }
  </style>
